package com.slashmanx.goals2u;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MatchScreen extends Activity 
{

	int matchID;
	
	TextView currentMinTV;
    TextView homeTeamTV;
    TextView homeScoreTV;
    TextView awayTeamTV;
    TextView awayScoreTV;
    public GoalsDatabaseManager db;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.match);
        
        Bundle extras = getIntent().getExtras();
        if(extras !=null) 
        {
        	matchID = extras.getInt("matchID");
        }
        
        TextView currentMinTV = (TextView) findViewById(R.id.currentMin);
        TextView homeTeamTV = (TextView) findViewById(R.id.homeTeam);
        TextView homeScoreTV = (TextView) findViewById(R.id.homeScore);
        TextView awayTeamTV = (TextView) findViewById(R.id.awayTeam);
        TextView awayScoreTV = (TextView) findViewById(R.id.awayScore);
        
        db = new GoalsDatabaseManager(this);
        
        Match currentMatch = db.getMatch(matchID);
        
        currentMinTV.setText("" + currentMatch.getMinute() + "'");
        homeTeamTV.setText(currentMatch.getHomeTeam());
        homeScoreTV.setText("" + currentMatch.getHomeScore());
        awayTeamTV.setText(currentMatch.getAwayTeam());
        awayScoreTV.setText("" + currentMatch.getAwayScore());
        
        
    }
    
    public void onDestroy()
    {
    	super.onDestroy();
    	if(db != null)
		{
			db.close();
		}
		db = null;
    }
    
    public void onPause()
    {
    	super.onPause();
    	if(db != null)
		{
			db.close();
		}
		db = null;
    }
    
    public void onResume()
    {
    	super.onResume();
    	if(db != null)
		{
			db.close();
		}
    	db = new GoalsDatabaseManager(this); 
    }

	
}
